package com.xn.app.muying.adpter;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.bean.DoctorGsonBean;
import com.xn.app.muying.bean.DoctorListBean;
import com.xn.app.muying.util.HttpUtil;
import com.xn.app.muying.util.MyAlertDialog;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/3.
 */
public class DoctorListAdapter extends BaseAdapter{
    private final LayoutInflater inflater;
    private Context context;
    private ArrayList<DoctorListBean> list = new ArrayList<>();
    private Handler handler = new Handler();


    public DoctorListAdapter(Context context, Handler handler) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }
    public void getData(ArrayList<DoctorListBean> data) {
        this.list.clear();
        this.list.addAll(data);
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null){
            view = inflater.inflate(R.layout.activity_doctorlist_item,null);
            holder = new ViewHolder();
            holder.tv_name = (TextView) view.findViewById(R.id.activity_doctorlist_name);
            holder.tv_title = (TextView) view.findViewById(R.id.activity_doctorlist_title);
            holder.tv_content = (TextView) view.findViewById(R.id.activity_doctorlist_content);
            holder.tv_hosptial_grade = (TextView) view.findViewById(R.id.activity_doctorlist_grade);
            holder.tv_hosptial_name = (TextView) view.findViewById(R.id.activity_doctorlist_doctorname);
            holder.iv = (ImageView) view.findViewById(R.id.activity_doctorlist_iv);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_name.setText(list.get(i).getName());
        holder.tv_title.setText(list.get(i).getProfessionalTitle());
        holder.tv_hosptial_grade.setText(list.get(i).getPrimaryHospitalLevel());
        holder.tv_hosptial_name.setText(list.get(i).getPrimaryHospitalName());
        holder.tv_content.setText(list.get(i).getSpecialty());
        holder.iv.setTag(list.get(i).getPhotoUrl());
        HttpUtil.getBitMap(list.get(i).getPhotoUrl().toString(), handler, holder.iv);
        return view;
    }

    class ViewHolder{
        ImageView iv;
        TextView tv_name;
        TextView tv_title;
        TextView tv_hosptial_grade;
        TextView tv_hosptial_name;
        TextView tv_content;

    }
}
